package com.zyd.blog.controller;

import com.github.pagehelper.PageInfo;
import com.zyd.blog.business.entity.Type;
import com.zyd.blog.business.enums.ResponseStatus;
import com.zyd.blog.business.service.BizSmalltalktagsService;
import com.zyd.blog.business.vo.SmalltalktagsVO;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.persistence.beans.BizSmalltalktags;
import com.zyd.blog.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 说说-标签-控制器
 */
@RestController
@RequestMapping("/Smalltalktag")
public class SmalltalktagController {


    @Autowired
    BizSmalltalktagsService bizSmalltalktagsService;

    // 测试
    @RequestMapping("/test")
    public String test(String name){
        return "Hello "+name;
    }

    // 列表
    @PostMapping("/list")
    public PageResult list(SmalltalktagsVO vo) {
        PageInfo<BizSmalltalktags> pageInfo = bizSmalltalktagsService.findPageBreakByCondition(vo);
        return ResultUtil.tablePage(pageInfo);
    }

    //

    // 标签添加
    @PostMapping(value = "/add")
    public ResponseVO add(BizSmalltalktags bizSmalltalktags) {
        bizSmalltalktagsService.insert(bizSmalltalktags);
        return ResultUtil.success("说说标签添加成功！新标签 - " + bizSmalltalktags.getName());
    }

    // 删除
    @PostMapping(value = "/remove")
    public ResponseVO remove(Long[] ids) {
        if (null == ids) {
            return ResultUtil.error(500, "请至少选择一条记录");
        }
        for (Long id : ids) {
            bizSmalltalktagsService.removeByPrimaryKey(id);
        }
        return ResultUtil.success("成功删除 [" + ids.length + "] 个说说标签");
    }


    //查询单个
    @PostMapping("/get/{id}")
    public ResponseVO get(@PathVariable Long id) {
        return ResultUtil.success(null, this.bizSmalltalktagsService.getByPrimaryKey(id));
    }

    // 修改
    @PostMapping("/edit")
    public ResponseVO edit(BizSmalltalktags bizSmalltalktags) {
        try {
            bizSmalltalktagsService.updateSelective(bizSmalltalktags);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("说说-标签-修改失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }





}
